﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FamilyTree
{
    public partial class Memberadd : Form
    {
        public Memberadd()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("您输入的成员信息是：");
            sb.Append("\n ID：" + txtID.Text);
            sb.Append("\n 姓 名：" + textBox1.Text);
            sb.Append("\n 性 别：" + textBox2.Text);
            sb.Append("\n 生 日：" + textBox3.Text);
            sb.Append("\n 地 址：" + textBox4.Text);
            sb.Append("\n 父 亲：" + textBox5.Text);
            sb.Append("\n 母 亲：" + textBox6.Text);
            sb.Append("\n 字 辈：" + textBox7.Text);
            MessageBox.Show(sb.ToString(), "请检查...", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string connString = @"Data Source = PC-20190806MQPW\SQLEXPRESS01; Initial Catalog = 终极电子族谱; User ID = sa; Password = 123456"; //数据库连接
            string sql = @"INSERT INTO member VALUES('" + txtID.Text + "','" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','"+textBox7.Text+"','"+textBox8.Text+"')";
            SqlConnection conn = new SqlConnection(connString);
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            try
            {
                cmd.ExecuteNonQuery();
                MessageBox.Show("信息已存入数据库！");
            }
            catch (Exception msg)
            {
                MessageBox.Show("出问题了！\n出错原因：" + msg.Message);
            }
            conn.Close();
        }

        private void Memberadd_Load(object sender, EventArgs e)
        {

        }
    }
}
